<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$register=uni_setting('register');
	$return['post']=array('more_mobile'=>$register['more_mobile']);
	set_html('title','找回密码');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$register=uni_setting('register');
	if(!$postdata['username'] && $postdata['needusername'] && $register['more_mobile']){
		exi('请输入要找回的账户名！','error');
	}
	if(!check_sms_code($postdata['smscode'])){
		exi('手机验证码错误！','error');
	}
	if(strlen($postdata['mobile'])!=11 || $postdata['mobile'][0]!='1' || !is_numeric($postdata['mobile'])){
		exi('手机号码格式错误，请输入11位，1开头的手机号！！','error');
	}
	if(!$postdata['password'] || !$postdata['password2']){
		exi('请输入新密码和重复新密码！','error');
	}
	if($postdata['password']!=$postdata['password2']){
		exi('新密码和重复新密码,不一直！','error');
	}
	if($register['more_mobile'] && $postdata['username']){
		$member=pdo_get('core_members',array('username'=>trim($postdata['username']),'mobile'=>trim($postdata['mobile']),'uniacid'=>$_SESSION['uniacid']),array('id'));
		if(!$member['id']){
			exi('该账户名绑定的手机不匹配！','error');
		}
		$uid=$member['id'];
	}else{
		$member=pdo_get('core_members',array('mobile'=>trim($postdata['mobile']),'uniacid'=>$_SESSION['uniacid']),array('id','onemid'));
		$uid=$member['onemid']?:$member['id'];
	}
	$update=array();
	$salt=random(10);
	$update['password']=get_password($postdata['password'],$salt);
	$update['salt']=$salt;
	pdo_update('core_members',$update,array('id'=>$uid,'uniacid'=>$_SESSION['uniacid']));
	exi('设置成功！','','/member.login/');
}